<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色权限</title>
<style type="text/css">
	body{
		text-align: center;
	}
	table thead{
		background-color: #AAD4FF;
	}
	table tbody{
		background-color: #E1E1E1;
	}
	table tfoot {
	background-color: #FAD0FA;
}
table tfoot input{
	background-color: #2AA9FE;
	margin-left: 20px;
	cursor: pointer;
}
</style>
<SCRIPT type="text/javascript">

	//修改状体
	function changeValue(inputTag){
		inputTag.value=inputTag.checked;
	}
	
	
	function checkDate(roleid){
		var urlPath="";
		var tds = document.getElementsByTagName("form")[0]
						.getElementsByTagName("table")[0]
						.getElementsByTagName("tbody")[0]
						.getElementsByTagName("td");
		
		for(var i=0;i<tds.length;i++){
			var input = tds[i].getElementsByTagName("input");
			if(input[1].checked==true){
				var powerid = tds[i].getElementsByTagName("input")[0].value;
				if(urlPath==""){
					urlPath+="powerid="+powerid;
				}else{
					urlPath+="&powerid="+powerid;
				}
			}
		}
		
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {	
		    	document.getElementById("main_content").innerHTML=xmlhttp.responseText;
		    }
		}
		xmlhttp.open("POST","/control/mapping/role_updatePower.go?role.id="+roleid+"&"+urlPath,true);
		xmlhttp.send();
	}
	/**
	*刷新页面
	**/
	function goBack(){
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {	
		    	document.getElementById("main_content").innerHTML=xmlhttp.responseText;
		    }
		}
		xmlhttp.open("POST",backURL,true);
		xmlhttp.send();
	}
	//加载页面的时候回去访问路径
	var backURL;
	window.onload = function(){
		backURL=document.URL;
	}
	</SCRIPT>
</head>
<body>

<div id="main_content">
	<form>
		<table>
			<thead>
				<tr>
					<td colspan="5" style="text-align: center;">${role.name}</td>
				</tr>
			</thead>
			<tbody>
				<tr>
				<s:iterator value="powers" var="powers_list" status="st">
					<td>
						<input type="hidden" name="powerid" value="${powers_list.id }"/>
						<input type="checkbox" <s:if test="#powers_list.check">checked="checked"</s:if> name="check" value="${powers_list.check }" onclick="changeValue(this)"/>
						${powers_list.name }
					</td>
					<s:if test="#st.count%5==0">
						</tr><tr>
					</s:if>
				</s:iterator>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="5"><input type="button" value="&nbsp;确&nbsp;定&nbsp;" onclick="checkDate(${role.id})"/><input type="reset" value="&nbsp;取&nbsp;消&nbsp;"/></td>
				</tr>
			</tfoot>
		</table>
	</form>
	</div>

</body>
</html>